package com.zzxx.controller;

import com.github.pagehelper.PageInfo;
import com.zzxx.pojo.Orders;
import com.zzxx.pojo.Product;
import com.zzxx.service.OrdersService;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("ordersController")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @RequestMapping("/getById")
    @ResponseBody
    public Orders getOrdersById(String id){
        Orders orders = ordersService.findById(id);
        return orders;
    }

    @PutMapping("/save")
    @ResponseBody
    public void saveOrders(@RequestBody Orders orders){
        ordersService.update(orders);
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageInfo<Orders> getOrders(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2") Integer pageSize){
        PageInfo<Orders> pageInfo = ordersService.getAllOrders(pageNum,pageSize);
        return pageInfo;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public void deleteOrder(String id){
        ordersService.deleteById(id);
    }
}
